﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ActivitiesControl.Domain.DAL;
using ActivitiesControl.Domain.Utils;
using ActivitiesControl.Domain.Model.VOs;

namespace ActivitiesControl.Domain.Services.Impls
{
	internal abstract class BaseService
		: IBaseServices
	{
		public abstract event MessageHandler MessageRaised;
		
		private IRepositoryProvider repositoryProvider;
		
		private IActivityRepository activityRepository;
		private IProjectRepository projectRepository;
		private IResourceRepository resourceRepository;
		private IUserRepository userRepository;
		private ICustomerRepository customerRepository;
		
		private IRepositoryProvider RepositoryProvider 
		{
			get 
			{
				if (repositoryProvider == null)
					repositoryProvider = Assembler.GetRepositoryProvider();

				return repositoryProvider;
			}
			set { repositoryProvider = value; }
		}
		
		protected IActivityRepository ActivityRepository
		{ 
			get
			{
				if (activityRepository == null)
					activityRepository = RepositoryProvider.GetActivityRepository();

				return activityRepository;
			}
		}

		protected IProjectRepository ProjectRepository
		{
			get
			{
				if (projectRepository == null)
					projectRepository = RepositoryProvider.GetProjectRepository();

				return projectRepository;
			}
		}

		protected IResourceRepository ResourceRepository
		{
			get
			{
				if (resourceRepository == null)
					resourceRepository = RepositoryProvider.GetResourceRepository();

				return resourceRepository;
			}
		}

		protected IUserRepository UserRepository
		{
			get
			{
				if (userRepository == null)
					userRepository = RepositoryProvider.GetUserRepository();

				return userRepository;
			}
		}

		protected ICustomerRepository CustomerRepository
		{
			get
			{
				if (customerRepository == null)
					customerRepository = RepositoryProvider.GetCustomerRepository();

				return customerRepository;
			}
		}

		internal abstract void RaiseMessage(object sender, MessageEventArgs e);
	}
}
